'use strict';

angular.module('com.lx.ngsl.tjfx.controller', [])
	/**
	 * controller
	 */
  .controller('tjfxController', ['$scope', '$http', '$location', '$alert',  function($scope, $http, $location, $alert) {
	  $scope.count = [];
	  $scope.number = [];
	  $scope.tag = [];
	  $scope.wrong = [];
	  $scope.dataSet = [];
	  $scope.dataSet[0] = ['percent', 'num', 'tag'];
	  $http.get("/ngsl/v0/analysis").success(
				function(data, status) {
					$scope.num = data.num;
					$scope.tag = data.tag;
  					$scope.wrong = data.wrong;
  					$scope.passPercents = [];
  					for(var i = 0;i < $scope.num.length;i++){
  						if($scope.num[i] == 0){
  							$scope.passPercents[i] = 1;
  						}else{
  							$scope.passPercents[i] = ($scope.num[i] - $scope.wrong[i])/$scope.num[i];
  						}
  					}
  					for(var j = 1; j <= $scope.num.length; j++ ){
  						var arr = [];
  						arr[0] = $scope.passPercents[j-1];
  						arr[1] = $scope.num[j - 1];
  						arr[2] = $scope.tag[j-1];
  						$scope.dataSet[j] = arr;
  					}
					var option = {
						    dataset: {
						        source: $scope.dataSet
						    },
						    grid: {containLabel: true},
						    xAxis: {name: '试题数量'},
						    yAxis: {name:'考察点',type: 'category'},
						    visualMap: {
						        orient: 'horizontal',
						        left: 'center',
						        min: 0,
						        max: 1,
						        text: ['通过率100%', '通过率0%'],
						        // Map the score column to color
						        dimension: 0,
						        inRange: {
						            color: ['#E15457','#D7DA8B']
						        }
						    },
						    series: [
						        {
						            type: 'bar',
						            encode: {
						                // Map the "amount" column to X axis.
						                x: 'num',
						                // Map the "product" column to Y axis
						                y: 'tag'
						            }
						        }
						    ]
						};

					  
					  	 //初始化echarts实例
						var wrong = echarts.init(document.getElementById('wrong'));//入库数据统计
						wrong.clear();

					//使用刚指定的配置项和数据显示图表。
						wrong.setOption(option);
				}).error(function(data, status) {
  					alert(data.error);
  					
					$scope.data = data || "Request failed";
					$scope.status = status;
		});
	  
	
  }])
	
  	







